x = ['+', '-', '*', '/']
def fun(k, l, i):
    """
    两个数据之间的运算
    :param k:
    :param l:
    :param i:
    :return:
    """
    if i==0:
        if (type(k) is int or type(k) is float) and (type(l) is int or type(l) is float):
            tem = k + l
            return tem
        else:
            return
    elif i==1:
        if (type(k) is int or type(k) is float) and (type(l) is int or type(l) is float):
            tem = k - l
            return tem
        else:
            return
    elif i==2:
        if (type(k) is int or type(k) is float) and (type(l) is int or type(l) is float):
            tem = k * l
            return tem
        else:
            return
    elif i==3:
        if (type(k) is int or type(k) is float) and (type(l) is int or type(l) is float):
            if l != 0:
                tem = k / l
                return tem
            else:
                return
        else:
            return
def calculate(y):
    """
    计算，求出符合要求的
    :return:
    """
    result_list = []
    result_list2 = []
    temp = 0
    temp1 = 0
    temp2 = 0
    for i in range(0,4):
        for j in range(0,4):
            for k in range(0,4):
                for l in range(0,4):
                    if i == j or i == k or i == l or j == k or j == l or k == l:
                        continue
                    else:
                        for n in range(0,4):
                            for m in range(0,4):
                                for p in range(0,4):
                                    for q in range(0,6):
                                        result = 0
                                        if q == 0:
                                            temp1 = fun(y[i], y[j], n)
                                            temp1 = fun(temp1, y[k], m)
                                            result = fun(temp1, y[l], p)
                                            if result==24:
                                                result_list.append(
                                                    "(({0}{1}{2}){3}{4}){5}{6}=24".format(y[i], x[n], y[j], x[m], y[k],
                                                                                          x[p], y[l]))
                                                result_list2.append(
                                                    "(({0}{1}{2}){3}{4}){5}{6}".format(y[i], x[n], y[j], x[m], y[k],
                                                                                       x[p], y[l]))
                                                # print("(({0}{1}{2}){3}{4}){5}{6}=24".format(y[i], x[n], y[j], x[m], y[k],
                                                #                                             x[p], y[l]))
                                                temp += 1
                                            #break
                                            continue
                                        elif q == 1:
                                            temp1 = fun(y[i], y[j], n)
                                            temp2 = fun(y[k], y[l], p)
                                            result = fun(temp1, temp2, m)
                                            if result == 24:
                                                result_list.append(
                                                    "({0}{1}{2}){3}({4}{5}{6})=24".format(y[i], x[n], y[j], x[m], y[k],
                                                                                          x[p], y[l]))
                                                result_list2.append(
                                                    "({0}{1}{2}){3}({4}{5}{6})".format(y[i], x[n], y[j], x[m], y[k],
                                                                                       x[p], y[l]))
                                                # print("({0}{1}{2}){3}({4}{5}{6})=24".format(y[i], x[n], y[j], x[m], y[k],
                                                #                                             x[p], y[l]))
                                                temp += 1
                                            #break
                                            continue
                                        elif q == 2:
                                            temp1 = fun(y[j], y[k], m)
                                            temp1 = fun(y[i], temp1, n)
                                            result = fun(temp1, y[l], p)
                                            if result == 24:
                                                result_list.append(
                                                    "({0}{1}({2}{3}{4})){5}{6}=24".format(y[i], x[n], y[j], x[m], y[k],
                                                                                          x[p], y[l]))
                                                result_list2.append(
                                                    "({0}{1}({2}{3}{4})){5}{6}".format(y[i], x[n], y[j], x[m], y[k],
                                                                                       x[p], y[l]))
                                                # print("({0}{1}({2}{3}{4})){5}{6}=24".format(y[i], x[n], y[j], x[m], y[k],
                                                #                                             x[p], y[l]))
                                                temp += 1
                                            # break
                                            continue
                                        # elif q==3:
                                        #     temp1 = fun(y[k], y[l], m)
                                        #     temp2 = fun(y[i], y[j], p)
                                        #     result = fun(temp1, temp2, n)
                                        #     if result == 24:
                                        #
                                        #         print("({0}{1}{2}){3}({4}{5}{6})=24".format(y[i], x[n], y[j], x[m], y[k],
                                        #                                                     x[p], y[l]))
                                        #         temp += 1
                                        #         break
                                        elif q == 3:
                                            temp1 = fun(y[j], y[k], m)
                                            temp1 = fun(temp1, y[l], p)
                                            result = fun(y[i], temp1, n)
                                            if result == 24:
                                                result_list.append(
                                                    "{0}{1}(({2}{3}{4}){5}{6})=24".format(y[i], x[n], y[j], x[m], y[k],
                                                                                          x[p], y[l]))
                                                result_list2.append(
                                                    "{0}{1}(({2}{3}{4}){5}{6})".format(y[i], x[n], y[j], x[m], y[k],
                                                                                       x[p], y[l]))
                                                # print("{0}{1}(({2}{3}{4}){5}{6})=24".format(y[i], x[n], y[j], x[m], y[k],
                                                #                                             x[p], y[l]))
                                                temp += 1
                                            #break
                                            continue
                                        elif q == 4:
                                            temp1 = fun(y[k], y[l], p)
                                            temp1 = fun(y[j], temp1, m)
                                            result = fun(y[i], temp1, n)
                                            if result == 24:
                                                result_list.append(
                                                    "{0}{1}({2}{3}({4}{5}{6}))=24".format(y[i], x[n], y[j], x[m], y[k],
                                                                                          x[p], y[l]))
                                                result_list2.append(
                                                    "{0}{1}({2}{3}({4}{5}{6}))".format(y[i], x[n], y[j], x[m], y[k],
                                                                                       x[p], y[l]))
                                                # print("{0}{1}({2}{3}({4}{5}{6}))=24".format(y[i], x[n], y[j], x[m], y[k],
                                                #                                             x[p], y[l]))
                                                temp += 1
                                            #break
                                            continue
    return temp, result_list, result_list2
    # if temp == 0:
    #     print("这四张牌无法完成24点游戏")
    # else:
    #     print()
def player():
    '''
    玩家输入
    :return:
    '''
    a = int(input("请输入第一个数:"))
    b = int(input("请输入第二个数:"))
    c = int(input("请输入第三个数:"))
    d = int(input("请输入第四个数:"))
    y=[a,b,c,d]
    result, result_list, result_list2 = calculate(y)
    print("这四张牌所有的组合为：")
    for i in result_list:
        print("{0}".format(i))
player()
# def input_number():
#     a = int(input("请输入第一个数:"))
#     b = int(input("请输入第二个数:"))
#     c = int(input("请输入第三个数:"))
#     d = int(input("请输入第四个数:"))
#     return a,b,c,d
